package com.library.view.components;

import io.yukk1o.easytermui.base.BaseComponent;
import io.yukk1o.easytermui.util.PrintUtils;

public class CommonButton extends BaseComponent {
    private final Runnable action;
    private final String title;

    public CommonButton(int relX, int relY, String title, Runnable action) {
        super(relX, relY, title.length(), 1);
        this.action = action;
        this.title = title;
    }


    @Override
    public void renderContext() {
        PrintUtils.printAt(absY, absX, title);
    }

    @Override
    public void handleClick(int x, int y) {
        action.run();
    }
}
